<template>
  <div class="situation-page">
    <div class="page-header">
      <el-button class="back-button" icon="el-icon-back" @click="goback">返回</el-button>
      <div class="page-title">党费金额详情</div>
    </div>
    <div class="page-body">
      <div class="table-search">
        <el-form inline>
          <el-form-item label="所属组织">
            <ClassifyTreeSelect
              @input="getBranchId"
              @getValue="getBranchNode"
              :value="queryParams.partyOrgId"
              size="mini"
            />
          </el-form-item>
          <el-form-item label="党员姓名">
            <el-input v-model="queryParams.name" size="mini" placeholder="请输入" />
          </el-form-item>
          <el-form-item>
            <el-button size="mini" type="primary" @click="search">搜索</el-button>
            <el-button size="mini" @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
        <el-form inline>
          <el-form-item>
            <el-button size="mini" type="primary" @click="openAdd">新增</el-button>
            <el-button
              size="mini"
              type="primary"
              @click="exportData"
              :disabled="multipleSelection.length===0"
            >导出</el-button>
            <el-button
              size="mini"
              type="success"
              @click="send"
              :disabled="multipleSelection.length===0"
            >批量发送提醒</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="table-box">
        <el-table
          :data="tableData"
          ref="table"
          height="100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column align="center" type="selection" width="50"/>
          <el-table-column prop="partyOrgName" align="center" label="所属组织" min-width="180" />
          <el-table-column prop="name" align="center" label="姓名" width="120" />
          <el-table-column prop="contributionBase" align="center" label="缴费基数" width="180" />
          <el-table-column prop="monthlyPartyDues" align="center" label="每月党费" width="180" />
          <el-table-column prop="year" align="center" label="年份" width="120" />
          <el-table-column prop="startMonth" align="center" label="开始月份" width="80" />
          <el-table-column prop="endMonth" align="center" label="结束月份" width="80" />
          <el-table-column prop="partyDuesDue" align="center" label="应缴党费" width="180" />
          <el-table-column align="center" label="操作" width="150">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="openEdit(scope.row)">修改</el-button>
              <el-button type="text" size="mini" @click="send(scope.row)">提醒</el-button>
              <el-button
                type="text"
                size="mini"
                @click="openDelete(scope.row)"
                style="color:#F56C6C;"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getData"
      />
    </div>
    <addOrEditPerson ref="addOrEditPerson" @getData="getData" />
  </div>
</template>
<script>
import addOrEditPerson from './addOrEditPerson'
import ClassifyTreeSelect from '@/components/classifyTree/classifyTreeSelect.vue'
import { queryDuesByCondition, deleteDuesById } from '@/api/cadreBusiness/feeAmountManagement'
export default {
  components: { addOrEditPerson, ClassifyTreeSelect },
  data () {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        partyOrgId: '',
        name: ''
      },
      total: 0,
      tableData: [],
      id: '',
      multipleSelection: []
    }
  },
  methods: {
    init ({ id }) {
      this.id = id
      this.queryParams.pageNo = 1
      this.getData()
    },
    search () {
      this.queryParams.pageNo = 1
      this.getData()
    },
    getData () {
      const obj = { ...this.queryParams, partyMemberInfoMgmtId: this.id }
      queryDuesByCondition(obj).then((res) => {
        this.tableData = res?.data?.records || []
        this.total = res?.data?.total || 0
      })
    },
    exportData () {
      this.clearCheck()
    },
    send (row) {
      this.clearCheck()
    },
    goback () {
      this.$emit('goback')
    },
    openAdd () {
      this.$refs.addOrEditPerson.open({ partyMemberInfoMgmtId: this.id })
    },
    getBranchNode (node) {
      this.queryParams.partyOrgId = node?.id || null
      // this.queryParams.partyOrgName = node?.fullNamePartyOrg || null
    },
    getBranchId (id) {
      // console.log('id', id)
    },
    openEdit (row) {
      const obj = { ...row, partyMemberInfoMgmtId: this.id }
      this.$refs.addOrEditPerson.open(obj)
    },
    openDelete (row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteDuesById({ id: row.id }).then((res) => {
          this.$message.success('删除成功')
          this.getData()
        })
      })
    },
    reset () {
      this.queryParams.partyOrgId = ''
      this.queryParams.name = ''
      this.search()
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    clearCheck () {
      this.$refs.table.clearSelection()
      this.multipleSelection = []
    }
  }
}
</script>
<style scoped lang="scss">
.page-header {
  display: flex;
  height: 60px;
  align-items: center;
  border-bottom: 1px solid #ddd;
  .back-button {
    margin-right: 16px;
  }
  .page-title {
    font-size: 18px;
    font-weight: 600;
  }
}
.page-body {
  padding-top: 16px;
  .table-search {
    display: flex;
    justify-content: space-between;
  }
  .table-box {
    height: calc(100vh - 280px);
    .click-span {
      cursor: pointer;
      color: #409EFF;
    }
  }
}

</style>
